<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="作品ID" prop="videoId" label-width="100">
        <el-input
          v-model="queryParams.videoId"
          placeholder="请输入作品ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作品状态" prop="videoStatus">
        <el-select v-model="queryParams.videoStatus" placeholder="请选择作品状态" clearable size="small" style="width:180px"
                   @keyup.enter.native="handleQuery">
          <el-option v-for="item in videoStatusTag" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="评论人用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入评论人用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评论人用户昵称" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入评论人用户昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评论内容" prop="reviewContent">
        <el-input
          v-model="queryParams.reviewContent"
          placeholder="请输入评论内容"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评论时间">
        <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd"
                        type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['store:review:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="videoList" @selection-change="handleSelectionChange" :max-height="tableHeight()">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="评论ID" align="center" prop="reviewId" width="180"/>
      <el-table-column label="作品ID" align="center" prop="videoId" width="180"/>
      <el-table-column label="作品状态" align="center" prop="videoStatus">
        <template v-slot="scope">
          <dic-staus-tag :options="videoStatusTag" :staus="scope.row.videoStatus"></dic-staus-tag>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="userName" />
      <el-table-column label="评论人用户ID" align="center" prop="userId" />
      <el-table-column label="评论人用户昵称" align="center" prop="userName"/>
      <el-table-column label="评论内容" align="center" prop="reviewContent" :show-overflow-tooltip="true"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="150"/>
      <el-table-column label="评论点赞数" align="left" prop="reviewUpvoteNum" >
        <template slot-scope="scope"><span class="info-num">{{ scope.row.reviewUpvoteNum }}</span></template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="300" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['store:review:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改家乡印象-作品对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body destroy-on-close>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="用户昵称 : " prop="userName">
          <span>{{ form.userName }}</span>
        </el-form-item>
        <el-form-item label="作品标题 : " prop="videoTitle">
          <span>{{ form.videoTitle }}</span>
        </el-form-item>
        <el-form-item label="作品内容 : " prop="videoContent">
          <span>{{ form.videoContent }}</span>
        </el-form-item>
        <el-form-item label="作品视频 : " prop="videoResource" v-if="form.videoClassify === 0">
          <video width="500" v-if="videoDialog"  :id="'video'+form.videoId" height="270" class="tc-video-container" playsinline webkit-playinline x5-playinline></video>
        </el-form-item>
        <el-form-item label="作品图片 : " prop="videoResource" v-if="form.videoClassify === 1">
          <image-preview v-for="imgUrl in (form.pictureUrls.split(','))" :key="imgUrl" :src="imgUrl" :width="200" :height="200" />
        </el-form-item>

        <el-form-item label="绑定家乡 : " prop="hometownAddress">
          <span>{{ form.hometownAddress }}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改特色游玩对话框 -->
    <el-dialog :title="titleStatus" :visible.sync="openStatus" width="500px" append-to-body>
      <el-form ref="form" :model="formStatus" :rules="rulesStatus" label-width="80px">
        <el-form-item label="下架原因" prop="videoRemark">
          <el-input v-model="formStatus.videoRemark" placeholder="请输入下架原因"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancelStatus">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    delReview,
    listReview
  } from "@/api/store/review";
  import TCPlayer from "@/plugins/release/tcplayer.v5.1.0.min.js";

  export default {
  name: "Review",
  data() {
    return {
      videoStatusTag: [
        { value: 0, label: "下架", cssClass: "warning" },
        { value: 1, label: "上架", cssClass: "success" }
      ],
      tcPlayerId: 'tcPlayer',
      player: null,
      videoFileid: '',
      videoAppid: '',
      videoDialog:false,//查看录像
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 家乡印象-作品表格数据
      videoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      titleStatus: "",
      // 是否显示弹出层
      openStatus: false,

      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        hometownId: undefined,
        videoTitle: undefined,
        videoResource: undefined,
        videoType: undefined,
        videoClassify: undefined,
        videoStatus: undefined,
        videoUpvoteNum: undefined,
        videoReviewNum: undefined,
        videoHeat: undefined,
        videoRemark: undefined,
      },
      // 表单参数
      form: {},
      formStatus: {},
      // 表单校验
      rules: {
      },
      rulesStatus: {
        playRemark: [
          {required: true, trigger: "blur", message: "请输入下架原因"}
        ],
      }

    };
  },
  created() {
    this.getList();
  },
  mounted() {
  },
  methods: {
    /** 查询家乡印象-作品列表 */
    getList() {
      this.loading = true;
      listReview(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        console.log(response)
        this.videoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    tableHeight() {
      return document.body.clientHeight - 250;
    },
    addDateRange(params, dateRange) {
      let search = params;
      dateRange = Array.isArray(dateRange) ? dateRange : [];
      search['startDate'] = dateRange[0];
      search['endDate'] = dateRange[1];
      return search;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelStatus() {
      this.openStatus = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        videoId: undefined,
        userId: undefined,
        hometownId: undefined,
        videoTitle: undefined,
        videoResource: undefined,
        videoType: undefined,
        videoClassify: undefined,
        videoStatus: 0,
        videoUpvoteNum: undefined,
        videoReviewNum: undefined,
        videoHeat: undefined,
        videoRemark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
      this.formStatus = {
        videoId: undefined,
        type: undefined,
        videoStatus: undefined,
        status: undefined,
        videoRemark: undefined
      };
      this.resetForm("formStatus");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.reviewId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const reviewIds = row.reviewId || this.ids;
      let idList = [];
      if (Array.isArray(reviewIds)) {
        idList = reviewIds;
      } else {
        idList.push(reviewIds);
      }
      this.$modal.confirm('是否确定删除评论？').then(() => {
        this.loading = true;
        return delReview(idList);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/video/export', {
        ...this.queryParams
      }, `video_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.over-num {
  color: #F56C6C;
  font-weight: bold;
}

.loss-num {
  color: #67C23A;
  font-weight: bold;
}

.info-num {
  color: #606266;
  font-weight: bold;
}
</style>
